#ifndef _DVR_CMD_APP_H_
#define _DVR_CMD_APP_H_

#include "crossplat_def.h"
#include "protocol_info.h"
#include <stdint.h>
#include "file_ctrl.h"
#ifdef _HAVE_JT808_
#include "jt_video_client.h"
#endif
class CDVRCmd
{
public:
	CDVRCmd();
	~CDVRCmd();
public:
	int Init(SOCKET m_fd,int clientID);
	int AttachSocket(SOCKET m_fd_svr, struct sockaddr* client_addr, int client_len);
	int Destroy();

	//UI
	//FILE List
	int AnalysisCmd(unsigned char * cmd_buf,int cmd_len);
	int HannShake();
	int HeadBeat();

protected:
	uint32_t GetCRC32_FromBuf(unsigned char * cmd_buf,uint32_t data_sz);
	int ConnectProc(char sub_cmd,uchar_t * data_buf,int data_sz);
	int UICtrlProc(char sub_cmd,uchar_t * data_buf,int data_sz);
	int FastCtrlProc(char sub_cmd,uchar_t * data_buf,int data_sz);
	int FileCtrlProc(char sub_cmd,uchar_t * data_buf,int data_sz);
	int CfgGetProc(char sub_cmd,uchar_t * data_buf,int data_sz);
	int CfgSetProc(char sub_cmd,uchar_t * data_buf,int data_sz);
	int ReplayCtrlProc(char sub_cmd,uchar_t * data_buf,int data_sz);
	int LiveCtrlProc(char sub_cmd,uchar_t * data_buf,int data_sz);
	int DiskMangerProc(char sub_cmd,uchar_t * data_buf,int data_sz);
	int CheckCRC32(unsigned char * cmd_buf,uint32_t len);
	int LuaRunProc(char sub_cmd, uchar_t* data_buf, int data_sz);
	//server
	int RespondDataPkt(char * buf, int data_sz);

	//client App
	int SendPkt(char * buf, int data_sz,char cmd_main,char cmd_sub);
	void BindClientID(int clientID)
	{
		m_clientID = clientID;
	}
private:
	SOCKET  m_fd;
	struct sockaddr* m_pClient_addr;
	int     m_client_len;
	time_t  m_heat_last;  //最后一次发送心跳包的时间
	#ifdef _HAVE_JT808_
	jt_video_client  m_ftp_client;
	#endif
	char *  m_sbuf;  //发送缓冲
	int     m_sbuf_sz;  //发送缓冲大小
	int     m_clientID; //客户端ID
	bool    m_bUdp;    //是否为UDP协议
	HEART_BEAT_RET m_beart;
	CFileInfo_manager m_fInfoManger;
};

#endif //_DVR_CMD_APP_H_
